import Vue from 'vue'
import VueRouter from 'vue-router'
import wsbroute from './modules/wsbroute'
import rqroute from './modules/rqroute'
import srjroute from './modules/srjroute'
import zyxroute from './modules/zyxroute'
import zsjroute from './modules/zsjroute'
import lyjroute from './modules/lyjroute'

Vue.use(VueRouter)

const routes = [
  {
    path: "/login",
    name: "login",
    component: () => import('../views/rq/LoginView.vue'),
  },

  {
    path: '/home',
    name: 'home',
    component: () => import('../views/HomeView.vue'),

    //二级路由
    children: [
      //任倩
      ...rqroute,
      //张银霞
      ...zyxroute,
      //史润洁
      ...srjroute,
      //张思瑾
      ...zsjroute,
      //李玉娇
      ...lyjroute,
      //王思博
      ...wsbroute,
    ]
  },
  //重定向
  {
    path: "/",
    redirect: "/login",

  },
  //404
  {
    path: "*",
    name: "404",
    component: () => import('../views/NoView.vue'),
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})


router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    next()
  } else {
    // 判断token
    if (window.sessionStorage.getItem("token")) {
      next()
    } else {
      next('/login')
    }
  }
})



export default router
